package com.cimpm.task.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.cimpm.permission.service.impl.DataPermissionServiceImpl;
import com.cimpm.task.entity.TaskFlow;
import com.hby.common.callback.AutoProcessControllerPart;
import com.hby.common.entities.aspect.parameter.ParamConverter;
import com.hby.common.entities.aspect.parameter.ServiceInfo;
import com.hby.common.exceptions.AutoException;
import com.hby.common.exceptions.ExceptionEnum;
import com.hby.common.services.Impl.mian.AutoEntityServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class TaskFlowServiceImpl extends AutoEntityServiceImpl<TaskFlow> {

    @Autowired
    private DataPermissionServiceImpl dataPermissionService;

    @Override
    public void customService(AutoProcessControllerPart autoProcessControllerPart, ServiceInfo serviceInfo) throws Throwable {

    }

    public Object getTaskFlowCanEdit(ParamConverter param, Integer userId, String userName) throws Throwable{
        String dataPermName = dataPermissionService.getDataPerm(userId, 0);
        QueryWrapper<TaskFlow> wrapper = new QueryWrapper<>();
        if (dataPermName.equals("default")){
            wrapper.eq("type",1);
            return mapper.selectList(wrapper);
        }else if (dataPermName.equals("taskManager")){
            return null;
        }else if (dataPermName.equals("taskAdmin")){
            List<TaskFlow> a= new ArrayList<>();
            return null;
        }else return new ArrayList<>();
    }

    public Object getTaskFlowCanProcess(ParamConverter param, Integer userId, String userName) throws Throwable{
        String dataPermName = dataPermissionService.getDataPerm(userId, 0);
        QueryWrapper<TaskFlow> wrapper = new QueryWrapper<>();
        if (dataPermName.equals("default")){
            wrapper.eq("type",1);
            return mapper.selectList(wrapper);
        }else if (dataPermName.equals("taskManager")){
            return null;
        }else if (dataPermName.equals("taskAdmin")){
            return null;
        }else throw new AutoException(ExceptionEnum.NOT_EXIST,"task permission type not exist");
    }
}
